﻿using System;
using System.Collections.Generic;
using System.Text;
using OVS.CoreDomain.Data;
using OVS.CoreDomain;
using System.Data;


namespace OVS.Data
{
    public class DalDistrict : Dal<IDistrict, District>, IDalDistrict
    {
        
        
        private const string SP_GET_DISTRICTS= "usp_GetDistricts";

         private readonly IDalManager _manager;
        private static readonly IDalDistrict _instance = new DalDistrict();

        public static IDalDistrict Instance
        {
            get { return _instance; }
        }

        public DalDistrict()
        {
            _manager = new DalManager();
        }

        public DalDistrict(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IDistrict obj, DataRow row)
        {
            obj.DistrictId = _manager.GetValue<string>(row, "DistrictId");
            obj.DistrictName = _manager.GetValue<string>(row, "DistrictName");
           
        }

    
        
        #region IDalDistrict Members

        public IList<IDistrict> GetDistricts()
        {
            _manager.StoredProcedureName = SP_GET_DISTRICTS;

            List<IDistrict> listDistricts = new List<IDistrict>();
            foreach (IDistrict district in ConvertAll(_manager.ExecuteDataSet()))
                listDistricts.Add(district);



            return listDistricts;

        }

        #endregion
    }
}
